import os
from dotenv import load_dotenv
from google.adk.models.lite_llm import LiteLlm
from pydantic.type_adapter import P

load_dotenv()

# 环境变量配置
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
BASE_URL = os.getenv("BASE_URL") 
MODEL = os.getenv("MODEL")

# 检查LLM配置是否完整
LLM_CONFIGURED = all([OPENAI_API_KEY, BASE_URL, MODEL])

def create_llm_model():
    if not LLM_CONFIGURED:
        raise ValueError("LLM配置不完整")
    
    return LiteLlm(
        model=MODEL,
        api_base=BASE_URL,
        api_key=OPENAI_API_KEY,
        extra_headers={"X-DashScope-DataInspection": "{\"input\":\"disable\", \"output\":\"disable\"}"}
    )

def get_llm_config():
    return {
        "configured": LLM_CONFIGURED,
        "api_key": OPENAI_API_KEY,
        "base_url": BASE_URL,
        "model": MODEL
    }